<?php

/**
 * Project: Espolon
 * Licence: BSD License
 * Link: http://espolon.org/
 * Copyright: Nicolas de Bari Embriz Garcia Rojas <nbari at espolon dot org>
 * Author: Nicolas de Bari Embriz Garcia Rojas <nbari at espolon dot org>
 * Version: Beta
 */

if (!defined('SITE_ROOT')) exit('No direct script access allowed');

/**
 * Start the roles object
 */

$command = isset($options[1]) ? $options[1] : null;
$rid = isset($options[2]) ? $options[2] : null;
$role = new Roles();

switch ($command) {
  case 'modify':
    check_rid($rid);
    $command_tpl = 'modify_role.tpl';
    $role->setRid($rid);
    $form = new ModifyRole($tpl, $role);
    if ($form->validate()) {
      $form->freeze();
      $form->process();
    } else {
      $form->displayForm();
    }
  break;
  case 'delete':
    check_rid($rid);
    $command_tpl = 'delete_role.tpl';
    $role->setRid($rid);
    $tpl->assign('role_name',$role->getRoleName());
    $tpl->assign('rid', $rid);
    if (isset($options[3]) AND $options[3] == 'true') {
      $role->deleteRole();
      $this->tpl->assign('result',true);
    }

  break;
  default:
    $form = new AddRole($tpl, $role);
    if ($form->validate()) {
      $form->freeze();
      $form->process();
      $tpl->assign('roles', $role->getRoles());
    } else {
      $form->displayForm();
      $tpl->assign('roles', $role->getRoles());
    }
}


/**
 * show the errors
 */
if ($role->getMsg()) {
  $tpl->assign('msg', $role->getMsg());
}
?>